<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>轨迹回放</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
        }

        .input-card .btn{
            margin-right: 1.2rem;
            width: 9rem;
        }

        .input-card .btn:last-child{
            margin-right: 0;
        }
    </style>
</head>
<body>
<div id="container"></div>
<div class="input-card">
    <h4>学生48h行踪轨迹</h4>
    <div class="input-item">
        <input type="button" class="btn" value="开始动画" id="start" onclick="startAnimation()"/>
        <input type="button" class="btn" value="暂停动画" id="pause" onclick="pauseAnimation()"/>
    </div>
    <div class="input-item">
        <input type="button" class="btn" value="继续动画" id="resume" onclick="resumeAnimation()"/>
        <input type="button" class="btn" value="停止动画" id="stop" onclick="stopAnimation()"/>
    </div>
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=cf5617fb9e043ca3221c1187abdeaf83"></script>
<script>
    var xhttp=new XMLHttpRequest();
    locall();


    var marker, lineArr = [[120.4383,30.449135],[120.438536,30.448368],[120.437721,30.448164],
    [120.437324,30.447961],[120.436337,30.448664],[120.436197,30.449163],
    [120.438804,30.44945],[120.440295,30.449718],[120.440092,30.450726],
    [120.439802,30.45203],[120.439265,30.452613],[120.438965,30.45388],[120.437699,30.453482],
    [120.438085,30.452169],[120.438987,30.452863],[120.438987,30.452863],[120.438987,30.452863],
    [120.43977,30.452076],[120.440156,30.450911]];
    var line=[[120.436337,30.448664],[120.436197,30.449163],
    [120.438804,30.44945],[120.440295,30.449718],[120.440092,30.450726],
    [120.439802,30.45203],[120.439265,30.452613],[120.438965,30.45388],[120.437699,30.453482],
    [120.438085,30.452169],[120.438987,30.452863]];

    var  route;
    console.log(route);
    function locall(){
        xhttp.onreadystatechange = function () {
            if (this.readyState === 4 && this.status === 200) {
                const obj = JSON.parse(this.responseText);
                if (obj.success){
                    var i=0;
                    var a1 = [];
                    for(let loca of obj.data){
                        a1[i] = [loca.lng,loca.lat];
                        i=i+1;

                    }
                    route=a1;
                  }}
        };
        xhttp.open("GET", "/route", true);
        xhttp.setRequestHeader('Accept', 'application/json');
        xhttp.send();
    }
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [120.4383,30.449135],
        zoom: 17
    });

    marker = new AMap.Marker({
        map: map,
        position: [120.439552,30.447664],
        icon: "./ma.jpg",
        offset: new AMap.Pixel(-26,-13),
        autoRotation: true,
        angle:-90,
    });

    // 绘制轨迹
    var polyline = new AMap.Polyline({
        map: map,
        path: route,
        showDir:true,
        strokeColor: "#28F",  //线颜色
        // strokeOpacity: 1,     //线透明度
        strokeWeight: 6,      //线宽
        // strokeStyle: "solid"  //线样式
    });

    var passedPolyline = new AMap.Polyline({
        map: map,
        // path: route,
        strokeColor: "#AF5",  //线颜色
        // strokeOpacity: 1,     //线透明度
        strokeWeight: 6,      //线宽
        // strokeStyle: "solid"  //线样式
    });


    marker.on('moving', function (e) {
        passedPolyline.setPath(e.passedPath);
    });

    map.setFitView();


    function startAnimation () {
        marker.moveAlong(route, 1000);//移动的速度
    }

    function pauseAnimation () {
        marker.pauseMove();
    }

    function resumeAnimation () {
        marker.resumeMove();
    }

    function stopAnimation () {
        marker.stopMove();
    }
    // window.onload=function () {
    //     locall();
    // }
</script>
</body>
</html>


<!-- select latitude,longitude from (select * from(select row_number() over (order by time) as rn,
    * from temperature1) t)s where rn%2=1 -->

    <!--  SELECT * FROM "biao name" WHERE time > now() - 7d -->
    <!-- select * from temperature1 where time >='1652778391195000000' and time <='1652778642995000000' group by time(1m);     -->